<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
    <meta name="author" content="火星科技 http://mars3d.cn " />
    <meta name="apple-touch-fullscreen" content="yes" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="x5-fullscreen" content="true" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
    <!-- 标题及搜索关键字 -->
    <meta name="keywords" content="火星科技,cesium,3D,GIS,marsgis,三维,地球,地图,开发,框架,系统,示例,资料,模型,离线,外包,合肥,安徽,中国" />
    <meta
      name="description"
      content="火星科技 合肥火星 合肥火星科技 合肥火星科技有限公司 leaflet leaflet框架 leaflet开发 cesium cesium开发 cesium框架 三维 地球 模型  gis marsgis 地图离线 地图开发 地图框架 地图外包 框架 开发 外包  地图离线 二维地图 三维地图 全景漫游 地理信息系统 云GIS 三维GIS GIS平台 WebGIS"
    />

    <link rel="shortcut icon" type="image/x-icon" href="http://mars3d.cn/favicon.ico" />
    <title>通视分析 demo | Mars3D | 三维地图 | 火星科技 | 合肥火星科技有限公司</title>

    <!--第三方lib-->
    <script
      type="text/javascript"
      src="../lib/include-lib.js"
      libpath="../lib/"
      include="jquery,font-awesome,bootstrap,layer,haoutil,turf,mars3d"
    ></script>
    <link href="css/style.css" rel="stylesheet" />
  </head>

  <body class="dark">
    <!--加载前进行操作提示，优化用户体验-->
    <div id="mask" class="signmask" onclick="removeMask()"></div>

    <div id="mars3dContainer" class="mars3d-container"></div>

    <!-- 面板 -->
    <div class="infoview">
      <input type="button" class="btn btn-primary" value="通视分析" onclick="drawLine()" />
      <input type="button" class="btn btn-primary" value="圆形通视分析" onclick="drawCircle()" />
      <input type="button" class="btn btn-primary" value="清除" onclick="clearAll()" />

      <a href="editor.html#k10_sightline_terrain" target="_blank" class="btn btn-default">地形精确分析示例</a>
    </div>

    <div id="tipView" class="info-tips">
      (1) 依赖cesium底层接口，部分情况下不够准确<br />
      (2) 目标点如果在观察位置坡面的背面方向，会出现不准确现象
    </div>

    <!-- 切换视角到模型或地形（山区）的快捷按钮 -->
    <script type="text/javascript" src="js/center_terrain_3dtiles.js"></script>

    <script src="./js/common.js"></script>
    <script type="text/javascript">
      "use script"; //开发环境建议开启严格模式

      var map;
      var sightline;

      function initMap(options) {
        //合并属性参数，可覆盖config.json中的对应配置
        var mapOptions = mars3d.Util.merge(options, {
          scene: {
            center: { lat: 30.715648, lng: 116.300527, alt: 10727, heading: 3, pitch: -25 },
            globe: {
              depthTestAgainstTerrain: false,
            },
          },
        });

        //创建三维地球场景
        map = new mars3d.Map("mars3dContainer", mapOptions);

        sightline = new mars3d.thing.Sightline({
          depthFailColor: Cesium.Color.fromCssColorString("#db2c8f"),
        });
        map.addThing(sightline);
      }

      function drawCircle() {
        map.graphicLayer.clear();
        map.graphicLayer.startDraw({
          type: "circle",
          style: {
            color: "#ffff00",
            opacity: 0.2,
            clampToGround: true,
          },
          success: function (graphic) {
            //绘制成功后回调

            var center = graphic.positionShow;
            center = mars3d.PointUtil.addPositionsHeight(center, 1.5); //加人的身高等因素，略微抬高一些

            var targetPoints = graphic.getOutlinePositions(false, 45);

            map.graphicLayer.clear();

            var targetArr = [];
            for (var i = 0; i < targetPoints.length; i++) {
              var targetPoint = targetPoints[i];
              targetPoint = mars3d.PointUtil.getSurfacePosition(map.scene, targetPoint);
              sightline.add(center, targetPoint);
            }

            createPoint(center, true);
          },
        });
      }

      function drawLine() {
        map.graphicLayer.clear();
        map.graphicLayer.startDraw({
          type: "polyline",
          maxPointNum: 2,
          style: {
            color: "#55ff33",
            width: 3,
          },
          success: function (graphic) {
            //绘制成功后回调
            var positions = graphic.positionsShow;
            map.graphicLayer.clear();

            var center = positions[0];
            var targetPoint = positions[1];
            sightline.add(center, targetPoint, { offsetHeight: 1.5 }); //1.5是加人的身高等因素，略微抬高一些

            createPoint(center, true);
            createPoint(targetPoint, false);
          },
        });
      }

      function clearAll() {
        sightline.clear();
        map.graphicLayer.clear();
      }

      function createPoint(position, isFirst) {
        var graphic = new mars3d.graphic.PointEntity({
          position: position,
          style: {
            color: Cesium.Color.fromCssColorString("#3388ff"),
            pixelSize: 6,
            outlineColor: Cesium.Color.fromCssColorString("#ffffff"),
            outlineWidth: 2,
            scaleByDistance: new Cesium.NearFarScalar(1.5e2, 1.0, 8.0e6, 0.2),
            label: {
              text: isFirst ? "观察位置" : "目标点",
              font_size: 17,
              font_family: "楷体",
              color: Cesium.Color.AZURE,
              outline: true,
              outlineColor: Cesium.Color.BLACK,
              outlineWidth: 2,
              horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
              verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
              pixelOffset: new Cesium.Cartesian2(0, -20), //偏移量
              distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 2000000),
            },
          },
        });
        map.graphicLayer.addGraphic(graphic);

        return graphic;
      }
    </script>
  </body>
</html>
